<template>
  <view class="resume-container">
    <view class="section">
      <text class="title">基本信息</text>
      <uni-forms :modelValue="resume">
        <uni-forms-item label="姓名">
          <input v-model="resume.name" placeholder="请输入姓名" />
        </uni-forms-item>
        <uni-forms-item label="手机号">
          <input v-model="resume.phone" placeholder="请输入手机号" />
        </uni-forms-item>
        <uni-forms-item label="邮箱">
          <input v-model="resume.email" placeholder="请输入邮箱" />
        </uni-forms-item>
      </uni-forms>
    </view>

    <view class="section">
      <text class="title">教育经历</text>
      <view v-for="(edu, index) in resume.education" :key="index" class="experience-item">
        <input v-model="edu.school" placeholder="学校名称" />
        <input v-model="edu.major" placeholder="专业" />
        <input v-model="edu.period" placeholder="时间段" />
        <button @click="removeEducation(index)">删除</button>
      </view>
      <button @click="addEducation">添加教育经历</button>
    </view>

    <view class="section">
      <text class="title">实习经历</text>
      <view v-for="(job, index) in resume.internship" :key="index" class="experience-item">
        <input v-model="job.company" placeholder="公司名称" />
        <input v-model="job.position" placeholder="职位" />
        <input v-model="job.period" placeholder="时间段" />
        <button @click="removeInternship(index)">删除</button>
      </view>
      <button @click="addInternship">添加实习经历</button>
    </view>

    <button class="submit-btn" @click="submitResume">提交简历</button>
  </view>
</template>

<script>
export default {
  data() {
    return {
      resume: {
        name: '',
        phone: '',
        email: '',
        education: [{ school: '', major: '', period: '' }],
        internship: [{ company: '', position: '', period: '' }],
      },
    };
  },
  methods: {
    addEducation() {
      this.resume.education.push({ school: '', major: '', period: '' });
    },
    removeEducation(index) {
      this.resume.education.splice(index, 1);
    },
    addInternship() {
      this.resume.internship.push({ company: '', position: '', period: '' });
    },
    removeInternship(index) {
      this.resume.internship.splice(index, 1);
    },
    submitResume() {
      uni.showLoading({ title: '提交中...' });
      uni.request({
        url: 'https://api.example.com/resume',
        method: 'POST',
        data: this.resume,
        success: (res) => {
          uni.showToast({ title: '提交成功', icon: 'success' });
        },
        fail: () => {
          uni.showToast({ title: '提交失败', icon: 'none' });
        },
        complete: () => uni.hideLoading(),
      });
    },
  },
};
</script>

<style>
.resume-container {
  padding: 20px;
}
.section {
  margin-bottom: 20px;
}
.title {
  font-size: 18px;
  font-weight: bold;
  margin-bottom: 10px;
}
.experience-item {
  margin-bottom: 10px;
}
.submit-btn {
  background-color: #4caf50;
  color: #fff;
  padding: 10px;
  text-align: center;
  border-radius: 5px;
}
</style>
